﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Caliburn.Testability;
using System.Windows;

namespace IronCommander
{
    public class DataBindingValidator
    {
        private static BindingValidator ValidatorFor(Type guiElement, Type presenterType)
        {
            var boundType = new BoundType(presenterType);
            var instance = (DependencyObject)Activator.CreateInstance(guiElement);
            var element = Bound.DependencyObject(instance, boundType);
            return new BindingValidator(element);
        }

        /// <summary>
        /// Validate the bindings of a keyvalue pair 
        /// where the key is the View type and the 
        /// value is the ViewModel type.
        /// </summary>
        public IEnumerable<ValidationResult> Validate(IDictionary<Type, Type> viewViewModelDictionary)
        {
            foreach (var viewViewModel in viewViewModelDictionary)
            {
                var validator = ValidatorFor(viewViewModel.Key, viewViewModel.Value);
                var validatorResult = validator.Validate();
                yield return validatorResult;
            }
        }
    }
}
